
#include "stdafx.h"

#include "../../loader.h"
using namespace dlguif;

#include <iostream>
using std::cout;
using std::cerr;
using std::endl;


Loader loader;


void CALLBACK OnGuiEvent(void* user_context, const callback_info* ci)
{
	static int count = 0;
	count ++;

	Loader* ploader = (Loader*)user_context;

	cout << "GUI event! " << count << endl;
	cout << "tag: " << ci->tag << endl;
	cout << "type: " << Loader::event_type_to_string(ci->eventType) << endl;
	cout << "Param1: " << ci->param1 <<  endl;
	cout << "Param2: " << ci->param2 <<  endl;
	cout << "Class name: " << ci->class_name << endl;
	cout << "Name: " << ci->name << endl;
	cout << "--------------------------" << endl;
 
	if(ci->eventType == EVENT_TYPE_FORM_CLOSE)
	{
		ploader->PostExit(0);
	}

}


int _tmain(int argc, _TCHAR* argv[])
{
//	Loader loader(L"j:/dlguif/dlguif/delphi_dll_project/dlguif.dll");
	loader.SetGuiEventCallBack(OnGuiEvent,  (void*)&loader );
	void* form = loader.CreateForm("caption", "myform", 10, 10, 800, 600);
	void* tv = loader.CreateTreeView(form, form, 
		&Loader::MakeRectangle(10, 10, 200, 300) );

 
	void* tvi0 = loader.CreateTreeViewItem(tv, NULL, "item0", NULL);
	void* tvi1 = loader.CreateTreeViewItem(tv, NULL, "item1", NULL);
	void* tvi2 = loader.CreateTreeViewItem(tv, NULL, "item2", NULL);

	void* tvichild = loader.CreateTreeViewItem(tv, "item1", "child", NULL);
 



	loader.ShowForm(form);

	//loader.Run();

	//while( loader.GetControlVisible(form) )
	//{
	//	loader.ProcessMessages();
	//	Sleep(1);
	//}

	 //loader.Run();
	while( loader.ProcessMessages() )
	{
		Sleep(1);
	}

 

	return 0;
}